package exercise;

/*
a.编写程序将 “jdk” 全部变为大写,并输出到屏幕,截取子串”DK” 并输出到屏幕
b.String s="name=zhangsan age=18 classNo=090728";
    将上面的字符串拆分，结果如下:
     zhangsan 180 90728
c.写一个方法判断一个字符串是否对称(对称是正反都一样的)

 */
public class ex01 {
    public static void main(String[] args) {
        String a = "jdk";
        a = a.toUpperCase();
        System.out.println("转大写：" + a.toUpperCase());
        System.out.println("截取子串：" + a.substring(1));

        System.out.println("---------------------------------------");

        String s = "name=zhangsan age=18 classNo=090728";
        String[] values = s.split(" ");
        for (String value : values) {
            System.out.print(value.split("=")[1] + " ");
        }

        System.out.println("\n---------------------------------------");

        System.out.println(isSymmetry("9123210"));
        System.out.println(isSymmetry("12321"));
        System.out.println(reverse("123456789"));
    }

    public static boolean isSymmetry(String str) {
        int i = 0, j = str.length() - 1;
        while (i < j) {
            if (str.charAt(i) != str.charAt(j)) {
                return false;
            }
            i++;
            j--;
        }
        return true;
    }

    public static String reverse(String str) {
        System.out.println("str = " + str);
        if (str.length() == 1) {
            return str;
        }
        return reverse(str.substring(1)) + str.charAt(0);
    }
}
